package com.nuoniu.sibanyun.mapper.so;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.nuoniu.sibanyun.entity.so.VSaleOrderDetail;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author baiqiang
 * @since 2020-11-26
 */
public interface VSaleOrderDetailMapper extends BaseMapper<VSaleOrderDetail> {

    @Delete("delete from scs_order_detail where order_id=#{orderId}")
    void removeByOrderId(Long orderId);

    @Update("update scs_order_detail set is_operation=1 where id=#{voucherId} ")
    void updateOperationStatus(Integer voucherId);

    @Select("select count(1) from scs_order_detail where is_operation=0 and order_id=#{orderId}")
    Integer getOperationCount(Integer orderId);

    @Select("select d.* from scs_order_detail d left join scs_order m on d.order_id=m.id where m.company_id=#{companyId} and m.voucher_state=1 and m.is_operation=0 ORDER BY d.order_id DESC")
    List<VSaleOrderDetail> getList(Integer companyId);


    boolean updateDetailGenerateWorkPlanStatus(Integer companyId,List<Long> detailIds, Integer status);

    Integer sumDetailNotGenerateWorkPlanStatus(Integer companyId,Long orderId,List<Long> detailIds);


}
